//
//  ViewController.swift
//  learnSwift01
//
//  Created by zmj27404 on 16/4/17.
//  Copyright © 2016年 zmj27404. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        testPlayer()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func testPlayer() {
        var player01 = Player(name: "zmj")
        var player02 = Player(name: "wjl")
        var player03 = Player(name: "baby01")
        var player04 = Player(name: "baby02")
        var playerArray01 = [player01, player02, player03, player04]
        
        func playerContinueGame(arr: [Player])  {
            for playerI in arr {
                let level = random() % 4
                playerI.completedLevel(level)
            }
            print("\(playerArray01)")
        }
        
        var time = dispatch_time(DISPATCH_TIME_NOW, Int64(1.5 * Double(NSEC_PER_SEC)))
        let queue_t = dispatch_get_main_queue()
        
        func afterPlayerGame () {
            print("延迟执行")
            dispatch_after(time, queue_t) {
                playerContinueGame(playerArray01)
                print("2秒后执行")
            }
        }
        afterPlayerGame()
    }
}

